<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- component是组件的占位符，我们可以指定究竟要让哪个组件显示在这个位置 -->
        <component :is="loc"></component>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>

        //首页的组件
        Vue.component("index", {
            template: "<h1>这是首页</h1>"
        })

        //登录页的组件
        Vue.component("login", {
            template: "<h1>这是登录页</h1>"
        })

        //详情页的组件
        Vue.component("detail", {
            template: "<h1>这是详情页</h1>"
        })

        var vm = new Vue({
            el: "#app",
            data: {
                loc: "index"
            },
            created(){
                this.loc = location.hash.slice(2);
                
                window.onhashchange = () => {
                    this.loc = location.hash.slice(2);
                }
            }
        })
    </script>
</body>

</html>